#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int search(vector<int>& nums, int target) {
        int begin = 0;
        int end = nums.size() - 1;
        int mid = begin + (end - begin) / 2;
        while (begin <= end)
        {
            if (nums[mid] < target)
                begin = mid + 1;
            else if (nums[mid] > target)
                end = mid - 1;
            else
                return mid;
            mid = begin + (end - begin) / 2;
        }
        return -1;
    }
};

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int left = 0;
        int right = nums.size() - 1;
        int len = 0;
        while (left <= right)
        {
            if (nums[right] == val)
                right--;
            if (nums[left] != val)
            {
                left++;
                len++;
            }
            if (left <= right)
                swap(nums[left], nums[right]);
        }
        return len;
    }
};

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int slow = 0;
        for (int fast = 0; fast < nums.size(); fast++)
        {
            if (nums[fast] != val)
                nums[slow++] = nums[fast];
        }
        return slow;
    }
};